package de.hft.st.algodat.ctt.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Solution {
	private int[][] solution;
	private List<Timeslot> tslots = new ArrayList<Timeslot>();
	private List<Room> rooms;
	private int days, periodsPerDay;

	public Solution(int days, int periodsPerDay, List<Room> rooms) {
		this.days = days;
		this.periodsPerDay = periodsPerDay;
		this.rooms = rooms;
		solution = new int[(days * periodsPerDay)][rooms.size()];
		int tsID = 0;
		for (int d = 1; d <= days; d++) {
			for (int ppd = 1; ppd <= periodsPerDay; ppd++) {
				for (Iterator<Room> itr = this.rooms.iterator(); itr.hasNext();) {
					tslots.add(new Timeslot(d, ppd, tsID, itr.next()));
				}
				tsID++;
			}
		}
	}

	public void setSolution(int[][] solution) {
		this.solution = solution;
	}

	public int[][] getSolution() {
		return solution;
	}

	public List<Timeslot> getTimeSlots() {
		return this.tslots;
	}

	public List<Timeslot> getAssignedTimeSlotsByTimeslot(Timeslot ts) {
		List<Timeslot> assigned = new ArrayList<Timeslot>();
		for (Iterator<Timeslot> itr = tslots.iterator(); itr.hasNext();) {
			Timeslot worker = itr.next();
			if (worker.getDay() == ts.getDay()
					&& worker.getPeriod() == ts.getPeriod()) {
				assigned.add(worker);
			}
		}
		return assigned;
	}

	@Override
	public String toString() {
		StringBuffer toStr = new StringBuffer();
		for (Iterator<Timeslot> itr = tslots.iterator(); itr.hasNext();) {
			Timeslot worker = itr.next();
			toStr.append(worker.toString());
		}
		return toStr.toString();
	}

	public void setAssignedCurriculaWithSameCourse(
			List<Curriculum> curriculaWithSameCourse, Course course,
			Timeslot dts) {
		for (Iterator<Curriculum> cItr = curriculaWithSameCourse.iterator(); cItr
				.hasNext();) {
			// Timeslot setTS = findTimeslotBy
		}

		// for (Iterator<Timeslot> itr = tslots.iterator(); itr.hasNext();) {
		// Timeslot worker = itr.next();
		// if (worker.isAssigned() && worker.getDay() == ts.getDay()
		// && worker.getPeriod() == ts.getPeriod()) {
		// assigned.add(worker);
		// }
		// }
	}

}
